From: Sebastian Keller Date: Thu, 4 Nov 2021 13:09:03 +0000 (+0100) Subject: calendar: Fix inclusion of zero-length events X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~536^2^2~61 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=225065367381252877bd54e25f7cdb8f71820ff5;p=gnome-shell.git calendar: Fix inclusion of zero-length events Events with a date time (not just a date) where the end time is missing or matching the start time were considered to not overlap the selected interval if they were happening on the start time of the interval. This was causing such zero-length events to be omitted from the calendar if they were starting at 0:00. Part-of: --- diff --git a/js/ui/calendar.js b/js/ui/calendar.js index ad8363558..a42d70ffb 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -171,13 +171,26 @@ function _datesEqual(a, b) { return true; } -function _dateIntervalsOverlap(a0, a1, b0, b1) { - if (a1 <= b0) +/** + * Checks whether an event overlaps a given interval + * + * @param {Date} e0 Beginning of the event + * @param {Date} e1 End of the event + * @param {Date} i0 Beginning of the interval + * @param {Date} i1 End of the interval + * @returns {boolean} Whether there was an overlap + */ +function _eventOverlapsInterval(e0, e1, i0, i1) { + // This also ensures zero-length events are included + if (e0 >= i0 && e1 < i1) + return true; + + if (e1 <= i0) return false; - else if (b1 <= a0) + if (i1 <= e0) return false; - else - return true; + + return true; } // an implementation that reads data from a session bus service @@ -343,7 +356,7 @@ class DBusEventSource extends EventSourceBase { *_getFilteredEvents(begin, end) { for (const event of this._events.values()) { - if (_dateIntervalsOverlap(event.date, event.end, begin, end)) + if (_eventOverlapsInterval(event.date, event.end, begin, end)) yield event; } }